#include <iostream>
using namespace std;
//作用:通过重载递增运算符,实现自己的整型数据
class MyInteger{
    friend ostream& operator<<(ostream& out,MyInteger myint);
public:
    MyInteger(){
        m_Num = 0;
    }
    //前置++
    MyInteger& operator++(){
        //先++
        m_Num++;
        //再返回
        return *this;
    }

    //后置++ 
    // MyInteger& operator++(int)  int代表占位参数,可以用于区分前置和后置递增
    MyInteger operator++(int){//这个必须返回值 而不是引用
        //先 记录当时结果
        MyInteger temp = *this;
        //后 递增
        m_Num++;
        //再返回
        return temp;
    }



private:
    int m_Num;
};

ostream& operator<<(ostream &out ,MyInteger myint){  //本质 operator << (cout , p) 简化 cout << p
    cout << myint.m_Num;
    return out;
  }

void test01(){
    MyInteger myint;
    cout << ++(++myint) << endl;
    cout << myint << endl;
}

void test02(){
    MyInteger myint;
    cout << myint++ << endl;
    cout << myint << endl;
}

int main(){
    test01();
	test02();
	system("pause");
	return 0;
}

